package com.xxjqr.rbac.service.impl;

import com.github.pagehelper.PageInfo;
import com.xxjqr.rbac.entity.dto.JobDto;
import com.xxjqr.rbac.entity.pojo.TbJob;
import com.xxjqr.rbac.entity.vo.JobVo;
import com.xxjqr.rbac.mapper.TbJobMapper;
import com.xxjqr.rbac.service.TbJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxjqr.rbac.util.SnowIdUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 岗位表 服务实现类
 * </p>
 *
 * @author 丁昌江
 * @since 2021-03-02
 */
@Service
@AllArgsConstructor
public class TbJobServiceImpl extends ServiceImpl<TbJobMapper, TbJob> implements TbJobService {

    private final TbJobMapper jobMapper;

    @Override
    public Boolean addJob(JobDto jobDto) {
        TbJob tbJob = new TbJob();
        BeanUtils.copyProperties(jobDto, tbJob);
        jobDto.setId(SnowIdUtil.nextId());
        return save(tbJob);
    }

    @Override
    public PageInfo<JobVo> getJobs(String code,String name,Integer status) {
        List<JobVo> jobVoList = jobMapper.getJobs(code, name, status);
        return PageInfo.of(jobVoList);
    }

    @Override
    public Boolean putJob(JobDto jobDto) {
        TbJob tbJob = new TbJob();
        BeanUtils.copyProperties(jobDto, tbJob);
        return updateById(tbJob);
    }

    @Override
    public List<JobVo> getJobList() {
        return jobMapper.getJobList();
    }
}
